﻿using RockBus.DataContracts;
using System;
using System.Collections.Generic;

namespace RockBus.ConfigurationRepository.SqlServer
{
    public class FilterInfoComparerForFilterReferences : IComparer<FilterInfo>
    {
        /// <summary>
        /// Sorts the filters so they can be inserted into the database in proper order.
        ///  Filters, that are referenced to by other filters, will be moved up the list.
        /// </summary>
        /// <param name="asc"></param>
        public FilterInfoComparerForFilterReferences(bool asc)
        {
            //if (!asc)
            //{
            //    this._val = -1;
            //}
        }

        //private int _val = 1;

        public int Compare(FilterInfo x, FilterInfo y)
        {
            string xid = "2" + x.Id;
            if (string.IsNullOrEmpty(x.Filter1Id) && string.IsNullOrEmpty(x.Filter2Id))
            {
                xid = "1" + x.Id;
            }

            string yid = "2" + y.Id;
            if (string.IsNullOrEmpty(y.Filter1Id) && string.IsNullOrEmpty(y.Filter2Id))
            {
                yid = "1" + y.Id;
            }

            return StringComparer.InvariantCultureIgnoreCase.Compare(xid, yid);
        }
    }
}